class Note < ActiveRecord::Base
  belongs_to :user
  belongs_to :resource
  	
  	def grade(value,userId)
  		note_grade = NoteGrade.find(:first , :conditions => "note_id = #{self.id} AND user_id = #{userId}")
  		if(note_grade.nil?) then
  			note_grade = NoteGrade.new
  			note_grade.evaluation = value
  			note_grade.note_id = self.id
  			note_grade.user_id = userId
  			note_grade.save
  		end
  	end
  	
  def Note.getVoteThisNote(userId,noteId)
  grade = 0
  note_grade = (NoteGrade.find(:first , :conditions => "user_id = #{userId} AND note_id = #{noteId}"))
  	 if (not note_grade.nil?) then
  	 	grade = note_grade.evaluation
  	 end
  return grade
  end
  
end
